//
//  GRPurchaseSuccessViewController.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/10.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRPurchaseSuccessViewController.h"
#import "ReturnIntegralView.h"
#import "MSTabBarController.h"
#import "GROrderManagerListViewController.h"
#import "GRConfirmOrderViewController.h"

//#import "GRShopCarViewController.h"
@interface GRPurchaseSuccessViewController ()
@property (weak, nonatomic) IBOutlet UIButton *homeBt;
@property(nonatomic,strong)ReturnIntegralView * intergralView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet UIButton *lookOrderBt;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topOffset;

@end

@implementation GRPurchaseSuccessViewController
-(BOOL)navigationShouldPopOnBackButton{
    UIViewController * listVC;
    for (UIViewController * VC in self.navigationController.viewControllers) {
//        if ([VC isKindOfClass:[GRGoodManagerViewController class]]) {
//            listVC = VC;
//        }
//        else
    
    if ([VC isKindOfClass:[GROrderManagerListViewController class]]){
            NSInteger index;
            if (self.successType == SuccessTypePay) {
                index = self.navigationController.viewControllers.count -3;
            }else{
                index = self.navigationController.viewControllers.count -2;
            }
            listVC = self.navigationController.viewControllers[index];
        }
    }
    if (listVC) {
        [self.navigationController popToViewController:listVC animated:YES];
    }else{
    [self.navigationController popViewControllerAnimated:YES];
    }
    return NO;
}

-(ReturnIntegralView *)intergralView {
    if (!_intergralView) {
        _intergralView = [[ReturnIntegralView alloc]init];
    }
    return _intergralView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib;
    self.topOffset.constant = 64;
    self.lookOrderBt.hidden = NO;
    self.navigationItem.title = @"提交成功";
    if (self.successType == SuccessTypePay) {//
        self.titleLabel.text = @"交易成功";
        self.contentLabel.text = @"平台将在1~3工作内进行发货";
    }else if (self.successType == SuccessTypeReturnGood){
        self.titleLabel.text = @"提交申请成功";
        self.contentLabel.text = @"平台将在24小时内处理\n进度可在【我的】-【退货/售后】查看";
    }else if(self.successType == SuccessTypeReturnMoney){
        self.titleLabel.text = @"退款成功";
        self.navigationItem.title = @"退款成功";
        self.contentLabel.text = @"";
    }else if (self.successType == SuccessTypeCancleOrder){
        self.navigationItem.title = @"取消成功";
        self.titleLabel.text = @"取消成功";
        self.contentLabel.text = @"";
    }else if (self.successType == SuccessTypeGiveRice){
        self.titleLabel.text = @"互赠成功";
        self.contentLabel.text = @"";
        self.topOffset.constant = 14;
        self.lookOrderBt.hidden = YES;
        
}
    [self.homeBt.layer setBorderColor: [HEXCOLOR(0xdddddd) CGColor]];
    [self.homeBt.layer setBorderWidth:1.0];

    if (_isAllPay && self.successType == SuccessTypePay) {
        
        self.intergralView.integral = [NSString stringWithFormat:@"%.2lf",self.incomePoint];
        [self.intergralView showIntegral];
    }

}


- (IBAction)checkOrderAction:(id)sender {
    if (self.successType == SuccessTypeReturnGood ||self.successType) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        UIViewController * listVC ;
        UIViewController * confriVC;
        for (UIViewController * controller in self.navigationController.viewControllers) {
            if([controller isKindOfClass:[GROrderManagerListViewController class]]){
                listVC = controller;
            }
            if ([controller isKindOfClass:[GRConfirmOrderViewController class]]) {
                confriVC = controller;
            }
        }
    if (listVC) {
        if (confriVC) {
               NSInteger index = self.navigationController.viewControllers.count -5;
            [self.navigationController popToViewController:self.navigationController.viewControllers[index] animated:YES];
        }else{
        NSInteger index = self.navigationController.viewControllers.count -3;
        [self.navigationController popToViewController:self.navigationController.viewControllers[index] animated:YES];
        }
        
    }else{
            GROrderManagerListViewController * listVC = [[GROrderManagerListViewController alloc]init];
             listVC.isPay = YES;
            [self.navigationController pushViewController:listVC animated:YES];
    
    }
    }

}

- (IBAction)goHomeAction:(id)sender {
    [MSTabBarController seletedTabIndex:0];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
